$(document).ready(function () {
	var ctx = $("#ctx").val();//获取服务器地址

	/***************************    活动列表页    ***************************/

	$("#btn-create").click(function () {
	});

	//取PV代码
	$("#btn-getcodePV").live("click", function () {
		var adgroupId = $(this).attr("value");
		var url = ctx + "/advertiser/main/ad/target/ad-group/getCodePV?adgroupId=" + adgroupId;
		$.getJSON(url, function (data) {
			var data_1 = data;
			$('.bootbox-body').text(data_1);
		});
		bootbox.dialog({
			message: "PV代码：",
			title: "PV代码",
			locale: 'zh_CN',
			buttons: {
				success: {
					label: "复制",
					className: "btn-success",
					callback: function () {
						var _content = $('.bootbox-body').text();
					}
				},
				main: {
					label: "关闭",
					className: "btn-primary",
					callback: function () {
					}
				}
			}
		});
		//以下代码实现复制功能，利用ZeroClipboard插件实现
		var client = new ZeroClipboard($('.btn-success'));
		client.on('ready', function (event) {
			// console.log( 'movie is loaded' );
			client.on('copy', function (event) {
				event.clipboardData.setData('text/plain', $('.bootbox-body').text());
			});
			client.on('aftercopy', function (event) {
				console.log('Copied text to clipboard: ' + event.data['text/plain']);
			});
		});
		client.on('error', function (event) {
			// console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
			ZeroClipboard.destroy();
		});
	});

	//取转化代码
	$("#btn-getcode").live("click", function () {
		var adgroupId = $(this).attr("value");
		var url = ctx + "/advertiser/main/ad/target/ad-group/getCode?adgroupId=" + adgroupId;
		$.getJSON(url, function (data) {
			var data_1 = data;
			$('.bootbox-body').text(data_1);
		});
		bootbox.dialog({
			message: "转化代码：",
			title: "转化代码",
			locale: 'zh_CN',
			buttons: {
				success: {
					label: "复制",
					className: "btn-success",
					callback: function () {
						var _content = $('.bootbox-body').text();
					}
				},
				main: {
					label: "关闭",
					className: "btn-primary",
					callback: function () {
					}
				}
			}
		});
		//以下代码实现复制功能，利用ZeroClipboard插件实现
		var client = new ZeroClipboard($('.btn-success'));
		client.on('ready', function (event) {
			// console.log( 'movie is loaded' );
			client.on('copy', function (event) {
				event.clipboardData.setData('text/plain', $('.bootbox-body').text());
			});
			client.on('aftercopy', function (event) {
				console.log('Copied text to clipboard: ' + event.data['text/plain']);
			});
		});
		client.on('error', function (event) {
			// console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
			ZeroClipboard.destroy();
		});
	});

	//取到达代码
	$("#btn-getcodeVisit").live("click", function () {
		var adgroupId = $(this).attr("value");
		var url = ctx + "/advertiser/main/ad/target/ad-group/getCodeVisit?adgroupId=" + adgroupId;
		$.getJSON(url, function (data) {
			var data_1 = data;
			$('.bootbox-body').text(data_1);
		});
		bootbox.dialog({
			message: "到达代码：",
			title: "到达代码",
			locale: 'zh_CN',
			buttons: {
				success: {
					label: "复制",
					className: "btn-success",
					callback: function () {
						var _content = $('.bootbox-body').text();
					}
				},
				main: {
					label: "关闭",
					className: "btn-primary",
					callback: function () {
					}
				}
			}
		});
		//以下代码实现复制功能，利用ZeroClipboard插件实现
		var client = new ZeroClipboard($('.btn-success'));
		client.on('ready', function (event) {
			// console.log( 'movie is loaded' );
			client.on('copy', function (event) {
				event.clipboardData.setData('text/plain', $('.bootbox-body').text());
			});
			client.on('aftercopy', function (event) {
				console.log('Copied text to clipboard: ' + event.data['text/plain']);
			});
		});
		client.on('error', function (event) {
			// console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
			ZeroClipboard.destroy();
		});
	});
	//状态全部、开启、停用
	if ($("#status").val() == 0 || $("#status").val() == "") {
		$("#selectBar_status a:first").addClass("selectBar_change");
		$("#status").val(0);
	}
	$("#selectBar_status a").each(function () {
		var value = $(this).attr("value");
		if ($("#status").val() == value) {
			$(this).addClass("selectBar_change").siblings('.selectBar_change').removeClass('selectBar_change');
		}
	});
	$("#selectBar_status a").click(function () {
		$("#status").val($(this).attr("value"));
		refreshData();
	});

	//开启,暂停
	$("#btn-enable,#btn-disable,#btn-delete").click(function () {
		if ($(this).attr("id") == "btn-enable") {
			url = ctx + "/advertiser/main/ad/target/ad-group/enable";
		} else if ($(this).attr("id") == "btn-disable") {
			url = ctx + "/advertiser/main/ad/target/ad-group/disable";
		} else if ($(this).attr("id") == "btn-delete") {
			url = ctx + "/advertiser/main/ad/target/ad-group/delete";
		}
		singleOper($(this), url);
	});

	//批量开启,批量暂停
	$("#all-btn-enable,#all-btn-disable,#all-btn-delete").click(function () {
		if ($(this).attr("id") == "all-btn-enable") {
			url = ctx + "/advertiser/main/ad/target/ad-group/enable";
		} else if ($(this).attr("id") == "all-btn-disable") {
			url = ctx + "/advertiser/main/ad/target/ad-group/disable";
		} else if ($(this).attr("id") == "all-btn-delete") {
			url = ctx + "/advertiser/main/ad/target/ad-group/delete";
		}
		batchOpear($(this), url);
	});

	/***************************    创建，编辑投放    ***************************/

	//请选择点击类型
	if ($("#main_perClickul").html()) {
		if ($("#perClickType").val() == 0 || $("#perClickType").val() == "") {
			$("#perClickul_span").text("请选择点击类型");
		}
		$('ul#perClick_son_ul li').each(function () {
			if ($(this).attr("value") == $("#perClickType").val()) {
				$("#perClickul_span").text($(this).text());
			}
		});
		$("#perClick_son_ul").hide();
		$('ul#perClick_son_ul li').live("click", function () {
			$(this).parents('li').find('span').text($(this).html());
			$("#perClickType").val($(this).attr("value"));
			$("#perClickTypeName").val($(this).text());
			$('#perClick_son_ul').hide(); //ul隐藏
		});
		$("#perClickul_span").on("click", function () {
			$('#perClick_son_ul').show(); //ul显示
		});
		$("#perClickul_box").mouseleave(function () {
			$('#perClick_son_ul').hide(); //ul隐藏
		});
	}

	//请选择曝光类型
	if ($("#main_perImpressionul").html()) {
		if ($("#perImpressionType").val() == 0 || $("#perImpressionType").val() == "") {
			$("#perImpressionul_span").text("请选择曝光类型");
		}
		$('ul#perImpression_son_ul li').each(function () {
			if ($(this).attr("value") == $("#perImpressionType").val()) {
				$("#perImpressionul_span").text($(this).text());
			}
		});
		$("#perImpression_son_ul").hide();
		$('ul#perImpression_son_ul li').live("click", function () {
			$(this).parents('li').find('span').text($(this).html());
			$("#perImpressionType").val($(this).attr("value"));
			$("#perImpressionTypeName").val($(this).html());
			$('#perImpression_son_ul').hide(); //ul隐藏
		});
		$("#perImpressionul_span").on("click", function () {
			$('#perImpression_son_ul').show(); //ul显示
		});
		$("#perImpressionul_box").mouseleave(function () {
			$('#perImpression_son_ul').hide(); //ul隐藏
		});
	}
	//请选择优先级
	if ($("#main_priorityul").html()) {
		if ($("#priority").val() == 0 || $("#priority").val() == "") {
			$("#priorityul_span").text("设置优先级");
		}
		$('ul#priority_son_ul li').each(function () {
			if ($(this).text() == $("#priority").val()) {
				$("#priorityul_span").text($(this).text());
			}
		});
		$("#priority_son_ul").hide();
		$('ul#priority_son_ul li').live("click", function () {
			$(this).parents('li').find('span').text($(this).html());
			$("#priority").val($(this).text());
			$('#priority_son_ul').hide(); //ul隐藏
		});
		$("#priorityul_span").on("click", function () {
			$('#priority_son_ul').show(); //ul显示
		});
		$("#priorityul_box").mouseleave(function () {
			$('#priority_son_ul').hide(); //ul隐藏
		});
	}

	if ($("#areasDiv").html()) {
		var areasgeoPopup = $("#areas_popup")[0];
		var GEO_list;
		$('#btn-areas').click(function () {
			if (!areasgeoPopup) {
				areasgeoPopup = new areasPopup({
					width: '746px',
					height: '435px',
					title: '地域定向设定'
				});
				var defaultValue = "不限";
				var input = $('#areas').trigger('change');
				var selectedIds = input.val() ? input.val().split(',') : null;
				$('#areasconfirm').click(function () {
					var pop = areasgeoPopup;
					areasgeoPopup.hide();
					input.val(Area.save());
					var id = 'areas', selected = Area.save();
					$('#' + id).val(selected);
					if (selected && $('input[type=checkbox]:not(:checked)').length) {
						//有选择 且 非全选的
						$('#count-' + id)[0].innerHTML = selected.split(',').length;
						$('#geo-all-' + id).hide();
						$('#geo-selected-' + id).show();
					} else {
						if (!$('input[type=checkbox]:not(:checked)').length) {
							$('#geo-all-' + id).find('.default_text')[0].innerHTML = defaultValue;
						} else {
							var val = defaultValue;
							$('#geo-all-' + id).find('.default_text')[0].innerHTML = decodeURIComponent(val);
						}
						$('#geo-all-' + id).show();
						$('#geo-selected-' + id).hide();
					}
					$(parent.document).trigger('setData');

				});
				//Area.init(GEO_LIST,selectedIds);
				if (GEO_list) areasgeoPopup.show();
				else {
					$.ajax({
						url: ctx + '/advertiser/main/ad/target/ad-group/getLocations',
						dataType: 'json',
						success: function (GEO_LIST) {
							Area.init(GEO_LIST, selectedIds);
							areasgeoPopup.show();
							GEO_list = GEO_LIST;
						},
						error: function () {
							alert('数据拉取失败，请检查您的网络连接是否可用');
						}
					});
				}
			} else {
				areasgeoPopup.show();
			}
		});

		$('#count-areas').click(function () {
			$('#btn-areas').trigger('click');
		});

		if ($('#areas').val()) {
			$('#geo-selected-areas').show();
			$('#geo-all-areas').hide();
			$('#count-areas')[0].innerHTML = $('#areas').val().split(',').length;
		} else {
			$('#geo-selected-areas').hide();
			$('#geo-all-areas').show();
		}

	}

	//时间定向
	$('#setting_list').unbind("mousedown").bind("mousedown", function () {
		var date = $("#dateRangePicker").val().split('to');
		var s_date = date[0];
		var e_date = date[1];
		var len_box = $(".time_box").find(".time_item").length;
		if (len_box > 6) {
			bootbox.alert("最多只能添加6个时段");
		} else {
			if (s_date != "" && e_date != "") {
				$("#quantum_list1").find("p").removeClass("pitchon");
				$('#setting_list').daterangepicker1({
					showDropdowns: true,
					linkedCalendars: true,
					autoUpdateInput: true,
					"startDate": s_date,
					"endDate": e_date,
					"minDate": s_date,
					"maxDate": e_date,
					locale: {
						direction: $('#rtl').is(':checked') ? 'rtl' : 'ltr',
						format: 'YYYY-MM-DD',
						separator: ' to ',
						applyLabel: '确定',
						cancelLabel: '取消',
						fromLabel: '起始时间',
						toLabel: '结束时间',
						daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
						monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
							'七月', '八月', '九月', '十月', '十一月', '十二月'],
						firstDay: 1
					}
				});
				$(".daterangepicker1").eq($(".daterangepicker1").length - 1).addClass("add");
			} else {
				bootbox.alert("请选择活动周期，在进行操作！");
			}
		}
	});

	if ($("#divLBS").html()) {
		$('#city_custom').cxSelect({
			selects: ['prov', 'city'],
			required: true,
			url: ctx + '/advertiser/main/ad/target/ad-group/getLocations'
		});
	}

	//初始校验表单
	if ($("#validateForm").html()) {
		$('#dateRangePicker').daterangepicker({
			showDropdowns: true,
			linkedCalendars: true,
			autoUpdateInput: true,
			locale: {
				direction: $('#rtl').is(':checked') ? 'rtl' : 'ltr',
				format: 'YYYY-MM-DD',
				separator: ' to ',
				applyLabel: '确定',
				cancelLabel: '取消',
				fromLabel: '起始时间',
				toLabel: '结束时间',
				daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
				monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
					'七月', '八月', '九月', '十月', '十一月', '十二月'],
				firstDay: 1
			}
		}, function (start, end, label) {//格式化日期显示框  
			$('#dateRangePicker').val(start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
			$(".setting .time_box").empty();
		});
		if ($(".add_activeTime").html()) {
			$('#dateRangePicker').val("");
		}
		$("#validateForm").autovalidate();
		$(".input-text").focus(function () {
			$(this).parent("div.input-group").find("span.help-inline").text("").removeClass("help-inline").addClass("spanVaildate");
		});
	}

	var time_item_index = 0;
	$(document).on('click', '.daterangepicker1.add .applyBtn', function () {
		if ($(".edit_timeDiv").html() && $(".time_box .time_item").length > 0) {
			time_item_index = $(".time_box .time_item").length + 10;
		}
		var date = $("#dateRangePicker").val().split('to');
		var s_date = date[0];
		var e_date = date[1];
		var checked_date = [];
		var len = $(".setting .time_item").length;
		for (var i = 0; i < len; i++) {
			var json_check = { "startDate": $(".time_item").eq(i).find(".start_date").val(), "endDate": $(".time_item").eq(i).find(".end_date").val() };
			checked_date.push(json_check);
		}
		var startDate = $(this).parents(".daterangepicker1").find("input[name='daterangepicker_start']").val();
		var endDate = $(this).parents(".daterangepicker1").find("input[name='daterangepicker_end']").val();
		var flag = true;
		for (var j = 0; j < checked_date.length; j++) {
			if (startDate < checked_date[j].startDate && endDate < checked_date[j].startDate) {
				console.log(startDate + ":" + endDate);
				console.log(flag + ":1");
			} else if (startDate > checked_date[j].endDate && endDate > checked_date[j].endDate) {
				console.log(flag + ":2");
			} else {
				flag = false;
			}
		}
		if (flag) {
			var timeData = "";
			var obj = $(this).parents(".daterangepicker1").find("#quantum_list1");
			if (obj.find(".pitchon").length) {
				timeData = obj.find(".pitchon").map(function (i, span) {
					return $(span).attr("title");
				}).toArray().join(',');
			} else {
				timeData = -1;
			}
			var html = '<div class="time_item" index="' + time_item_index + '"><p class="tr_data"><span class="inp"><input type="" class="start_date edit_time" readonly="readonly" value="' + startDate + '"></span><span class="inp"><input type="" class="end_date edit_time" readonly="readonly" value = "' + endDate + '"></span></p><button class="btn_del">删除</button><input class="json_date" type="hidden" value = "' + timeData + '"></div>';
			$(".setting .time_box").append(html);
		} else {
			bootbox.alert("请选择正确时间！");
		}
		time_item_index++;
	});
	var index_item = 0;
	$(document).on('click', '.daterangepicker1.edit .applyBtn', function () {
		var date = $("#dateRangePicker").val().split('to');
		var s_date = date[0];
		var e_date = date[1];
		var checked_date = [];
		var len = $(".setting .time_item").length;
		for (var i = 0; i < len; i++) {
			var json_check = { "startDate": $(".time_item").eq(i).find(".start_date").val(), "endDate": $(".time_item").eq(i).find(".end_date").val() };
			checked_date.push(json_check);
		}
		var startDate = $(this).parents(".daterangepicker1").find("input[name='daterangepicker_start']").val();
		var endDate = $(this).parents(".daterangepicker1").find("input[name='daterangepicker_end']").val();
		var timeData = "";
		var obj = $(this).parents(".daterangepicker1").find(".quantum_list");
		if (obj.find(".pitchon")) {
			timeData = obj.find(".pitchon").map(function (i, span) {
				return $(span).attr("title");
			}).toArray().join(',');
		} else {
			timeData = -1;
		}
		$(".time_box .time_item").each(function () {
			if (index_item == $(this).attr("index")) {
				$(this).find(".start_date").val(startDate);
				$(this).find(".end_date").val(endDate);
				$(this).find(".json_date").val(timeData);
			}
		});
	});
	$(document).on('mousedown', '.setting .tr_data', function () {
		var date = $("#dateRangePicker").val().split('to');
		var s_date = date[0];
		var e_date = date[1];
		var obj_tr = $(this);
		var th_date_s = $(this).find(".start_date").val();
		var th_date_e = $(this).find(".end_date").val();
		obj_tr.daterangepicker1({
			showDropdowns: true,
			linkedCalendars: true,
			autoUpdateInput: true,
			"startDate": th_date_s,
			"endDate": th_date_e,
			"minDate": s_date,
			"maxDate": e_date,
			locale: {
				direction: $('#rtl').is(':checked') ? 'rtl' : 'ltr',
				format: 'YYYY-MM-DD',
				separator: ' to ',
				applyLabel: '确定',
				cancelLabel: '取消',
				fromLabel: '起始时间',
				toLabel: '结束时间',
				daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
				monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
					'七月', '八月', '九月', '十月', '十一月', '十二月'],
				firstDay: 1
			}
		});
		var obj = $(".daterangepicker1").eq($(".daterangepicker1").length - 1);
		$(".daterangepicker1").eq($(".daterangepicker1").length - 1).find(".quantum_list p").removeClass("pitchon");
		var chose_time = obj_tr.parent().find(".json_date").val();
		console.log(chose_time);
		if (chose_time != -1 && chose_time != "") {
			var chose_arr = chose_time.split(",");
			for (var n = 0; n < chose_arr.length; n++) {
				$(".daterangepicker1").eq($(".daterangepicker1").length - 1).find(".quantum_list p").eq(chose_arr[n]).addClass("pitchon");
			}
		}
		index_item = $(this).parent(".time_item").attr("index");
		if (!obj.hasClass("edit")) {
			$(".daterangepicker1").eq($(".daterangepicker1").length - 1).addClass("edit");
			$(".daterangepicker1").eq($(".daterangepicker1").length - 1).attr("index", index_item);
		}
	});
	$(document).on('click', '.daterangepicker1 .cancelBtn', function () {
		$(this).parents(".daterangepicker1").css("display", "none");
	});
	$(document).on('click', '.time_box .time_item .btn_del', function () {
		$(this).parents(".time_item").remove();
	});
	$("#create-btn-save,#edit-btn-save").click(function () {
		$("div.input-group").find("span.help-inline").text("").removeClass("help-inline").addClass("spanVaildate");
		if (!$("#validateForm").validate()) {
			return false;
		}
		var checked_date = [];
		var len = $(".setting .time_item").length;
		var jsondata = "[";
		for (var i = 0; i < len; i++) {
			if (i == 0) {
				jsondata += '{"startDate":\"' + $(".time_item").eq(i).find(".start_date").val() + '\","endDate":\"' + $(".time_item").eq(i).find(".end_date").val() + '\","dehours":\"' + $(".time_item").eq(i).find(".json_date").val() + '\"}';
			} else {
				jsondata += ',{"startDate":\"' + $(".time_item").eq(i).find(".start_date").val() + '\","endDate":\"' + $(".time_item").eq(i).find(".end_date").val() + '\","dehours":\"' + $(".time_item").eq(i).find(".json_date").val() + '\"}';
			}
		}
		jsondata += "]";
		$("#sdayParting").val(jsondata);
		var falg = validateMoney();
		if (falg == false) {
			return false;
		}
		//提示操作系统选择
		var oslist = $("#osDiv input[type='checkbox']:checked");
		var osId = "";
		if (oslist.length > 0) {
			oslist.each(function () {
				osId += $(this).val() + ",";
			});
			if (osId != "") {
				osId = osId.substring(0, osId.length - 1);
			}
		}
		$("#os").val(osId);
		$("#validateForm").submit();
		return false;
	});

	$("#create-btn-cancel,#edit-btn-cancel").click(function () {
		window.location.href = ctx + "/advertiser/main/ad/target/ad-group/list?orderId=" + $("#orderId").val() + "&advertiserId=" + $("#advertiserId").val() + "&page=" + $('#page').val();
	});

	$("#totalBudget").blur(function () {
		validateMoney();
	});

	//操作系统
	if ($(".edit_osDiv").html()) {
		var osId = $("#os").val();
		var authArr = osId.split(",");
		var checkboxs = $("#osDiv input[type='checkbox']");
		checkboxs.each(function (i) {
			for (var i = 0; i < authArr.length; i++) {
				if ($(this).val() == authArr[i]) {
					$(this).attr("checked", "true");
				}
			}
		});
	}
});

function exportExcel_list() {
	var searchValue = $("#searchValue").val();
	if (searchValue == "请输入关键字") {
		searchValue = "";
	}
	var param = "?orderId=" + $("#orderId").val() + "&advertiserId=" + $("#advertiserId").val() + "&status=" + $("#status").val() + "&searchValue=" + searchValue;
	$("#exportExcel").attr("href", $("#ctx").val() + "/advertiser/main/ad/target/ad-group/exportAdGroupExcel" + param);
	return false;
}

function validateMoney() {
	var reg = /^\d{1,8}\.?\d{0,2}$/;
	var $this = $("#totalBudget");
	if ($this.val().match(reg) != null) {
		if (($this.val().indexOf('.') == -1 && $this.val().length > 8) || $this.val() <= 0) {
			$this.css("box-shadow", "0 0 6px #ff0000").attr('title', '总预算金额整数位最多8位');
			$this.parent("div").find("span.spanVaildate").html("总预算金额整数位最多8位");
			return false;
		} else if ($this.val() > parseInt($("#budget").val())) {
			$this.css("box-shadow", "0 0 6px #ff0000").attr('title', '总预算不能大于活动总预算');
			$this.parent("div").find("span.spanVaildate").html("总预算不能大于活动总预算");
			return false;
		} else {
			$this.css("box-shadow", "none").attr('title', '');
			$this.parent("div").find("span.spanVaildate").html("");
		}
	} else {
		$this.css("box-shadow", "0 0 6px #ff0000").attr('title', '总预算金额整数位最多8位且最多有2位小数');
		$this.parent("div").find("span.spanVaildate").html("总预算金额整数位最多8位且最多有2位小数");
		return false;
	}
}

function setting_date() {
	var str_date = $("#sdayParting").val();
	console.log(str_date);
	if (str_date != "") {
		var js_date = $.parseJSON(str_date);
		var html = "";
		for (var i = 0; i < js_date.length; i++) {
			console.log(js_date[i].dehours);
			html += '<div class="time_item" index="' + i + '"><p class="tr_data"><span class="inp"><input type="text" class="start_date edit_time" readonly="readonly" value="' + js_date[i].startDate + '"></span><span class="inp"><input type="text" class="end_date edit_time" readonly="readonly" value = "' + js_date[i].endDate + '"></span></p><button class="btn_del">删除</button><input class="json_date" type="hidden" value = "' + js_date[i].dehours + '"></div>';
		}
		$(".setting .time_box").append(html);
		$(".time_box .time_item .btn_del").bind("click", function (e) {
			$(this).parents(".time_item").remove();
		});
		$(".setting .tr_data").unbind("mousedown").bind("mousedown", function () {
			var date = $("#dateRangePicker").val().split('to');
			var s_date = date[0];
			var e_date = date[1];
			var obj_tr = $(this);
			var th_date_s = $(this).find(".start_date").val();
			var th_date_e = $(this).find(".end_date").val();
			obj_tr.daterangepicker1({
				showDropdowns: true,
				linkedCalendars: true,
				autoUpdateInput: true,
				"startDate": th_date_s,
				"endDate": th_date_e,
				"minDate": s_date,
				"maxDate": e_date,
				locale: {
					direction: $('#rtl').is(':checked') ? 'rtl' : 'ltr',
					format: 'YYYY-MM-DD',
					separator: ' to ',
					applyLabel: '确定',
					cancelLabel: '取消',
					fromLabel: '起始时间',
					toLabel: '结束时间',
					daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
					monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
						'七月', '八月', '九月', '十月', '十一月', '十二月'],
					firstDay: 1
				}
			});
			var obj = $(".daterangepicker1").eq($(".daterangepicker1").length - 1);
			$(".daterangepicker1").eq($(".daterangepicker1").length - 1).find(".quantum_list p").removeClass("pitchon");
			var chose_time = obj_tr.parent().find(".json_date").val();
			console.log(chose_time);
			if (chose_time != -1 && chose_time != "") {
				var chose_arr = chose_time.split(",");
				for (var n = 0; n < chose_arr.length; n++) {
					$(".daterangepicker1").eq($(".daterangepicker1").length - 1).find(".quantum_list p").eq(chose_arr[n]).addClass("pitchon");
				}
			}
			index_item = $(this).parent(".time_item").attr("index");
			if (!obj.hasClass("edit")) {
				$(".daterangepicker1").eq($(".daterangepicker1").length - 1).addClass("edit");
				$(".daterangepicker1").eq($(".daterangepicker1").length - 1).attr("index", index_item);
			}
		});
	}
}